﻿#pragma once

#include"Common.h"
#include"CentralCache.h"

//单例模式—饿汉模式
class CentralCache
{
public:
	static CentralCache* getInstance()
	{
		return &_sInstance;
	}

	// 获取⼀个⾮空的span
	Span* GetOneSpan(SpanList& list, size_t size);

	// 从中⼼缓存获取⼀定数量的对象给thread cache
	size_t FetchRangeObj(void*& start, void*& end, size_t batchNum, size_t size);

	// 将⼀定数量的对象释放到span跨度
	void ReleaseListToSpans(void* start, size_t size);
private:
	SpanList _spanLists[FREE_LIST_SIZE];

private:
	//私有化构造函数
	CentralCache() {}

	//防拷贝
	CentralCache(const CentralCache&) = delete;
	CentralCache& operator=(const CentralCache&) = delete;

	static CentralCache _sInstance;
};